
package com.jinbo.footmessage.order;

import android.app.Activity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jinbo.footmessage.R;
import com.jinbo.footmessage.httpbean.OrderBean;
import com.jinbo.footmessage.httpbean.OrdersBean;
import com.jinbo.footmessage.httpretrofit.BusinessController;
import com.jinbo.footmessage.httpretrofit.HttpProtocolFactory;
import com.jinbo.footmessage.httpretrofit.Listener;
import com.jinbo.footmessage.serverInf.ConfirmOrderActivity;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by jinbo on 2015/8/19.
 */
public class ConfirmedItemListViewAdapter extends BaseAdapter {
    List<OrderBean> orders;

    static class ViewHolder {
        CircleImageView head;
        TextView name;
        TextView content;

        TextView date;
        TextView time;

        TextView state;

        TextView total_price;

        LinearLayout ll;

    }

    private Activity context;

    public ConfirmedItemListViewAdapter(Activity context, List<OrderBean> datalist) {//ArrayList<OrderBean> datalist) {
        this.context = context;
        orders = datalist;
    }

    void setorders(List<OrderBean> datalist) {
        this.orders = datalist;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        // TODO Auto-generated method stub*//*
        if (orders != null) {
            return orders.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        if (orders != null) {
            return orders.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override

    public View getView(final int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_confirmed_item, null);
            holder = new ViewHolder();
            holder.head = (CircleImageView) convertView.findViewById(R.id.head);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            holder.date = (TextView) convertView.findViewById(R.id.date);
            holder.time = (TextView) convertView.findViewById(R.id.time);
            holder.state = (TextView) convertView.findViewById(R.id.state);
            holder.total_price = (TextView) convertView.findViewById(R.id.total_price);
            holder.ll = (LinearLayout) convertView.findViewById(R.id.ll);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OrderDetailActivity.launch(context,orders.get(position),OrderActivity.REQUEST_DETAIL);

            }
        });

        Glide.with(context)
                .load(HttpProtocolFactory.HOST_URL_USER + orders.get(position).worker.head)
                        // .placeholder(R.mipmap.ic_launcher)
                        // .crossFade()
                .into(holder.head);
        holder.name.setText(orders.get(position).worker.name);
        holder.content.setText(orders.get(position).content);
        holder.date.setText(orders.get(position).date);
        holder.time.setText(orders.get(position).begin_time + "-" + orders.get(position).end_time);
        holder.total_price.setText(orders.get(position).total_price + "元");
        switch (orders.get(position).kind) {
            case 1:
                holder.state.setText("已被技师接收");
                break;
            case 2:
                holder.state.setText("已被技师拒绝");
                break;
            case 3:
                holder.state.setText("已被技师完成");
                break;
            case 4:
                holder.state.setText("已被技师撤销");
                break;

        }
        return convertView;
    }
}
